<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>1</title>
    <script src="https://unpkg.com/vue"></script>
    <script>
        window=onload=function(){

            var app4 = new Vue({
                el: '#app-4',
                methods: {

                    addpeople: function () {
                        this.peoples.push({name: this.username, age: this.age,time:new Date()});

                    },

                removeall: function () {
                    this.peoples = [];
                },remove:function(index){
                        this.peoples.splice(index,1);
                    },
                },

                data: {

                    peoples: [
                        { name:'gyj',age:20,time:new Date() },
                        { name:'gyh',age:21,time:new Date() },
                    ]
                },
                filters: {
                    capitalize: function (value) {
                        if (!value) return ''
                        value = value.toString()
                        return value.charAt(0).toUpperCase() + value.slice(1);
                    }
                }

            })

            }


    </script>
</head>
<body>

<div id="app-4">
    <p>用户名</p>
    <input v-model="username">
    <p>年龄</p>
    <input v-model="age">
    <p>{{message}}</p>

    <button v-on:click="addpeople">添加</button>
    <button v-on:click="removeall">删除所有</button>
    <table border="1">
        <tr>
            <th>序号</th>
            <th>名字</th>
            <th>年龄</th>
            <th>添加时间</th>
            <th>操作</th>
        </tr>
        <tr v-for="(people,index) in peoples">
            <td>{{index+1}}</td>

            <td>{{people.name|capitalize}}</td>
            <td>{{people.age|capitalize}}</td>
            <td>{{people.time.getHours()+":"+people.time.getMinutes()+":"+people.time.getSeconds()}}</td>

           <td> <button v-on:click="remove(index)">删除</button></td>
        </tr>

    </table>
</div>
</body>
</html>